from django import forms
from web import models
from web.forms.bootstrap import BootstrapForm


class WikiModelForm(BootstrapForm, forms.ModelForm):
    class Meta:
        model = models.Wiki
        fields = ['title', 'content', 'parent']
        # widgets = {
        #     'content': forms.Textarea(attrs={'style': 'height:300px'})
        # }

    def __init__(self, request, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.fields['content'].widget.attrs.update({'style': 'height:300px'})

        data_list = models.Wiki.objects.filter(project=request.tracer.project).values_list('id', 'title')
        self.fields['parent'].choices = data_list
        self.fields['parent'].choices.append((None, "无"))
